/*
 * @Author: zhangyang
 * @Date: 2024-05-23 11:52:12
 * @LastEditTime: 2024-06-03 09:53:59
 * @Description: 
 */
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import '/pages/home.dart';

import '../pages/sub/bill_create.dart';
import '../pages/sub/categray_create.dart';
import 'i_router.dart';
import 'not_found_page.dart';

class Routes {
  static String home = '/';
  static String billCreate = '/bill_create';
  static String categrayCreate = '/categray_create';

  static final List<IRouterProvider> _listRouter = [];

  static final FluroRouter router = FluroRouter();

  static void initRoutes() {
    /// 指定路由跳转错误返回页
    router.notFoundHandler = Handler(
        handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
      debugPrint('未找到目标页');
      return const NotFoundPage();
    });

    router.define(Routes.home,
        handler: Handler(
            handlerFunc:
                (BuildContext? context, Map<String, List<String>> params) =>
                    const Home()));

    router.define(Routes.billCreate,
        handler: Handler(
            handlerFunc:
                (BuildContext? context, Map<String, List<String>> params) =>
                    const BillCreatePage()));

    router.define(Routes.categrayCreate,
        handler: Handler(
            handlerFunc:
                (BuildContext? context, Map<String, List<String>> params) =>
                    const CategrayCreatePage()));

    _listRouter.clear();

    /// 各自路由由各自模块管理，统一在此添加初始化
    // _listRouter.add(ShopRouter());
    // _listRouter.add(LoginRouter());
    // _listRouter.add(GoodsRouter());
    // _listRouter.add(OrderRouter());
    // _listRouter.add(StoreRouter());
    // _listRouter.add(AccountRouter());
    // _listRouter.add(SettingRouter());
    // _listRouter.add(StatisticsRouter());

    /// 初始化路由
    void initRouter(IRouterProvider routerProvider) {
      routerProvider.initRouter(router);
    }

    _listRouter.forEach(initRouter);
  }
}
